package com.burke.gwt.client;

import com.google.gwt.canvas.dom.client.Context2d;
import com.google.gwt.dom.client.ImageElement;

public class Person {
	  ImageElement image;
	  ImageElement standImage;
	  ImageElement jumpImage;
	  double rot;
	  double baseA, a, maxA;
	  public Vector pos, vel, goal;
	  double jumpHeight;
	   
	  public Rect targetRect;
	  
	  public int state;
	  
	  public int frame;

	  public Person(ImageElement standImage, ImageElement jumpImage) {
	    this.image = standImage;
	    this.standImage = standImage;
	    this.jumpImage = jumpImage;
	    this.rot = 0;
	    jumpHeight = 0;
	    
	    pos = new Vector(0,0);
	    targetRect = new Rect();
	    vel = new Vector(0,0);
	    baseA = a = 5;
	    maxA = 12;
	    
	    vel.y = 0;
	    
	  }
	  
	  public void draw(Context2d context) {
	    context.save();
	    context.translate(pos.x, pos.y);
	  //  context.rotate(rot);
	    context.drawImage(image, 0, 0);
	    context.restore();
	  }
	  
	  public void update() {
		  
		  switch (state) {
		  case 0:
			  image = standImage;
			  if (pos.y <= targetRect.top) { 
				  pos.y = targetRect.top;
				  vel.y = 0;
				  jumpHeight = 0;
				  a = baseA;
			  }
			  else {
				  vel.y = -a;
				  pos.y -= vel.y;
				  jumpHeight += vel.y;
			  }
			  
			  
			  break;
		  case 1:
			  image = jumpImage;
			  if (jumpHeight > 60) {
				  vel.y = -a;
			  }
			  else if (jumpHeight <= 0) {
				  vel.y = a;
			  }
			  
			  pos.y -= vel.y;
			//  if (pos.y < targetRect.top ) pos.y = targetRect.top; 
			  jumpHeight += vel.y;
			
			  
			  break;
		  }
		  
		  if (pos.y > targetRect.top ) pos.y = targetRect.top;
	  }
	  
	  
	  public void excite() {
		  a += 0.4;
		  if (a > maxA) a = maxA;
	  }
}


